package com.ak.javaee.rest;

import java.util.List;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import com.ak.javaee.ejb.SLSBMemberBean;
import com.ak.javaee.ejb.SLSBMemberBean2;
import com.ak.javaee.model.Member;

 
@Path("/secure/members")
@RequestScoped
public class MemberResourceRESTService {

	@EJB
	SLSBMemberBean memberBean;
	
	@EJB 
	SLSBMemberBean2 memberBean2;
	

	@GET
	@Path("/1")
	@Produces(MediaType.APPLICATION_XML)
	public List<Member> findMembers() {
		return memberBean.getMembers();
	}
	
	@GET
	@Path("/2")
	@Produces(MediaType.APPLICATION_XML)
	public List<Member> findMembers2() {
		return memberBean2.getMembers();
	}

	@GET
	@Path("/hello")
	@Produces(MediaType.TEXT_PLAIN)
	public String sayHello(@Context HttpServletRequest request,
			@Context HttpServletResponse response) {

		return "hello " + request.getUserPrincipal().getName()+ "logged in User a Business user ? : " + request.isUserInRole("businessowner");
	}

}
